package com.ruoyi.school.controller;

import io.swagger.annotations.ApiParam;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.school.domain.SchoolTdx;
import com.ruoyi.school.service.ISchoolTdxService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 投档线Controller
 *
 * @author zyf
 * @date 2024-09-10
 */
@RestController
@RequestMapping("/tdx")
public class SchoolTdxController extends BaseController {
    @Autowired
    private ISchoolTdxService schoolTdxService;

    /**
     * 获取学校列表
     *
     * @return 学校列表
     */
    @GetMapping("/getSchoolList")
    public AjaxResult getSchoolList() {
        List<String> list = schoolTdxService.getSchoolList();
        List<SchoolTdx> collect = list.stream().map(e -> {
            SchoolTdx schoolTdx = new SchoolTdx();
            schoolTdx.setSchoolName(e);
            return schoolTdx;
        }).collect(Collectors.toList());
        return success(collect);
    }

    /**
     * 获取学校专业列表
     *
     * @return 学校专业列表
     */
    @GetMapping("/getSpecialityList")
    public AjaxResult getSpecialityList(String schoolName) {
        List<String> list = schoolTdxService.getSpecialityList(schoolName);
        List<SchoolTdx> collect = list.stream().map(e -> {
            SchoolTdx schoolTdx = new SchoolTdx();
            schoolTdx.setSpecialityName(e);
            return schoolTdx;
        }).collect(Collectors.toList());
        return success(collect);
    }

    /**
     * 查询投档线列表
     */
    @RequiresPermissions("school:tdx:list")
    @GetMapping("/list")
    public TableDataInfo list(SchoolTdx schoolTdx) {
        startPage();
        List<SchoolTdx> list = schoolTdxService.selectSchoolTdxList(schoolTdx);
        return getDataTable(list);
    }

    /**
     * 导出投档线列表
     */
    @RequiresPermissions("school:tdx:export")
    @Log(title = "投档线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchoolTdx schoolTdx) {
        List<SchoolTdx> list = schoolTdxService.selectSchoolTdxList(schoolTdx);
        ExcelUtil<SchoolTdx> util = new ExcelUtil<SchoolTdx>(SchoolTdx.class);
        util.exportExcel(response, list, "投档线数据");
    }

    /**
     * 导入投档线列表
     */
    @RequiresPermissions("school:tdx:export")
    @Log(title = "投档线", businessType = BusinessType.EXPORT)
    @PostMapping("/excel")
    public AjaxResult addExcel(@ApiParam("excel文件") @RequestParam("file") List<MultipartFile> files)
            throws IOException {
        schoolTdxService.addExcel(files);
        return toAjax(true);
    }

    /**
     * 获取投档线详细信息
     */
    @RequiresPermissions("school:tdx:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(schoolTdxService.selectSchoolTdxById(id));
    }

    /**
     * 新增投档线
     */
    @RequiresPermissions("school:tdx:add")
    @Log(title = "投档线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchoolTdx schoolTdx) {
        return toAjax(schoolTdxService.insertSchoolTdx(schoolTdx));
    }

    /**
     * 修改投档线
     */
    @RequiresPermissions("school:tdx:edit")
    @Log(title = "投档线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchoolTdx schoolTdx) {
        return toAjax(schoolTdxService.updateSchoolTdx(schoolTdx));
    }

    /**
     * 删除投档线
     */
    @RequiresPermissions("school:tdx:remove")
    @Log(title = "投档线", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(schoolTdxService.deleteSchoolTdxByIds(ids));
    }
}
